*******************************************************************************
******************************  TABLE A1  *************************************
************  Randomization Balance by Gender and Condition  ******************
*******************************************************************************
clear all
set more off

//cd "C:\Users\ganth\Dropbox\StrengthInNumbersReplicationPackage\replicable\table_a1"


*ssc install balancetable

********************************************************************************

**Study 1
use "table_a1_dataset_1.dta", clear

vl create depvarlist = (age white married gpa leader international pincome political sexism)

balancetable (mean if maleMajority==1 & female==1) (mean if maleMajority==0 & female==1) (diff maleMajority if female==1) (mean if maleMajority==1 & female==0) (mean if maleMajority==0 & female==0) (diff maleMajority if female==0) $depvarlist using "table_a1.tex", oneline varlabels ctitles("Maj. Male" "Maj. Female" "Diff." "Maj. Male" "Maj. Female" "Diff.") groups("Female" "Male", pattern(1 0 0 1 0 0) leftc("Study 1")) leftcobservations("") starlevels(* 0.05 ** 0.01) format(%12.2f) replace

**Study 2
use "table_a1_dataset_2.dta", clear

vl create depvarlist = (age white married gpa leader international pincome political sexism)

balancetable (mean if maleMajority==1 & female==1) (mean if maleMajority==0 & female==1) (diff maleMajority if female==1) (mean if maleMajority==1 & female==0) (mean if maleMajority==0 & female==0) (diff maleMajority if female==0) $depvarlist using "table_a1.tex", oneline varlabels ctitles("Maj. Male" "Maj. Female" "Diff." "Maj. Male" "Maj. Female" "Diff.") groups("Female" "Male", pattern(1 0 0 1 0 0) leftc("Study 2")) leftcobservations("") starlevels(* 0.05 ** 0.01) format(%12.2f) append

**Combined 
append using "table_a1_dataset_1.dta"

balancetable (mean if maleMajority==1 & female==1) (mean if maleMajority==0 & female==1) (diff maleMajority if female==1) (mean if maleMajority==1 & female==0) (mean if maleMajority==0 & female==0) (diff maleMajority if female==0) $depvarlist using "table_a1.tex", oneline varlabels ctitles("Maj. Male" "Maj. Female" "Diff." "Maj. Male" "Maj. Female" "Diff.") groups("Female" "Male", pattern(1 0 0 1 0 0) leftc("Studies 1 + 2")) leftcobservations("") starlevels(* 0.05 ** 0.01) format(%12.2f) append

foreach study in 1 2 {
	foreach var in $depvarlist {
		foreach g in 1 0 {
			qui ttest `var' if female==`g' & study==`study', by(maleMajority)
			qui ret li
			local p_val = r(p)
			if `p_val'<0.01 {
				display "`var' for female=`g' in study `study': ***"
			}
			else if `p_val'<0.05 {
				display "`var' for female=`g' in study `study': **"
			}
		}

	}
}
foreach var in $depvarlist {
	foreach g in 1 0 {
		qui ttest `var' if female==`g', by(maleMajority)
		qui ret li
		local p_val = r(p)
		if `p_val'<0.01 {
			display "`var' for female=`g' in combined: ***"
		}
		else if `p_val'<0.05 {
			display "`var' for female=`g' in combined: **"
		}
	}

}
